﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Telerik.Web.UI;
namespace QuanLyKhachSan
{
    /// <summary>
    /// 
    /// </summary>
    public partial class UC_Phong_SoDoCay : System.Web.UI.UserControl
    {
        private int PhongID = 0;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                rtvPhong.NodeDataBound += new Telerik.Web.UI.RadTreeViewEventHandler(rtvPhong_NodeDataBound);
                Phong_Load();
                if (this.Request.QueryString["PhongID"] != null)
                {
                    PhongID = int.Parse(this.Request.QueryString["PhongID"].ToString());
                    RadTreeNode nodeFind = rtvPhong.FindNodeByValue(PhongID.ToString());
                    if (nodeFind!=null)
                    {
                        nodeFind.Selected = true;
                    }
                    
                }
            }
            catch (Exception ex)
            {
                
                throw ex;
            }
        }

        void rtvPhong_NodeDataBound(object sender, Telerik.Web.UI.RadTreeNodeEventArgs e)
        {
            try
            {
                string PhongID =  (e.Node.DataItem as DataRowView)["PhongID"].ToString();
                if (PhongID.IndexOf("LP")>=0)
                {
                    e.Node.NavigateUrl = ResolveUrl("~/Pages/QuanLyCaiDatGia.aspx?TabID=1");
                }
                else
                {
                    e.Node.NavigateUrl = ResolveUrl("~/Pages/QuanLyCaiDatGia.aspx?TabID=1&PhongID=" + (e.Node.DataItem as DataRowView)["PhongID"].ToString());
                }
                
            }
            catch (Exception ex)
            {
                
                throw ex;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        protected void Phong_Load()
        {
            try
            {
                rtvPhong.DataSource = PhongBLL.Phong_SoDoCay();
                rtvPhong.DataBind();
            }
            catch (Exception ex)
            {
                
                throw ex;
            }
        }
    }
}